package com.dq.Week2.day09.pritice;

public class Person implements Duelist {
    private String name;
    private int health;
    private int attackPower;

    public Person(String name, int health, int attackPower) {
        this.name = name;
        this.health = health;
        this.attackPower = attackPower;
    }


    @Override
    public String getName() {
        return name;
    }

    @Override
    public int getHealth() {
        return health;
    }

    @Override
    public int getAttackPower() {
        return attackPower;
    }

    @Override
    public void attack(Duelist target) {
        if (target.getHealth() > 0) {
            target.setHealth(target.getHealth() - this.getAttackPower());
            System.out.println(this.getName() + " attacks " + target.getName() + " for " + this.getAttackPower() + " damage.");
            if (target.getHealth() <= 0) {
                System.out.println(target.getName() + " has been defeated!");
            }
        }
    }

    // This method is used to set the health of a person after being attacked
    public void setHealth(int health) {
        this.health = health;
    }
}